﻿<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <title>原型应用-数组求和方法</title>
    <script>
    var arr1 = new Array(12, 55, 34, 78, 676);
    var arr2 = new Array(12, 33, 1);

    Array.prototype.sum = function() //class
        //arr1.sum=function ()				//行间样式
        {
            var result = 0;

            for (var i = 0; i < this.length; i++) {
                result += this[i];
            }

            return result;
        };

    alert(arr1.sum()); //855
    alert(arr2.sum()); //46
    </script>
</head>

<body>
</body>

</html>
